

package com.kimo.shop.admin.task;

import com.kimo.shop.bean.model.Product;
import com.kimo.shop.common.i18n.LanguageEnum;
import com.kimo.shop.service.*;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;


@Component("prodTask")
public class ProdTask {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ProductService productService;


    public void recoveryPreSaleProd(){
        logger.info("过了预售时间的商品，恢复成普通商品状态。。。");
        List<Product> products = productService.recoveryPreSaleProd();
        if(CollectionUtils.isEmpty(products)){
            return;
        }
        for (Product product : products) {
            //清除缓存
            productService.removeProdCacheByProdId(product.getProdId(), LanguageEnum.LANGUAGE_EN.getLang());
            productService.removeProdCacheByProdId(product.getProdId(),LanguageEnum.LANGUAGE_ZH_CN.getLang());
        }
    }


}
